if __name__ == "__main__":
    import sys
    allLines = []
    with open(sys.argv[1], encoding="utf-8") as f:
        allLines = [i.strip().replace("│", "").replace(
            "┌─表名────────────────────────────────────┬───总行数─┬─原始大小───┬─压缩大小───┬─压缩率─┐", "")
                    .replace(
            "└─────────────────────────────────────────┴──────────┴────────────┴────────────┴────────┘", "")
                    for i in f.readlines()]
    after = []
    for line in allLines:
        line = [i for i in line.strip().split(" ") if i != '' and i != '\n'][:-1]
        if len(line) != 0:
            after.append(line)
    map = {}
    m = {"TiB": 1024 * 1024 * 1024 * 1024,
         "GiB": 1024 * 1024 * 1024,
         "MiB": 1024 * 1024,
         "KiB": 1024,
         "B": 1}
    cast = {
        0: "B",
        1: "KiB",
        2: "MiB",
        3: "GiB",
        4: "TiB"
    }
    def trans(a, b):

        return int(float(a) * m[b])
    def trans2B(s):
        temp = s
        i = 0
        while temp >= 1024:
            temp /= 1024
            i += 1
        return f'{temp:.2f}' + " " + cast[i]


    for line in after:
        # print(line)
        if line[0] not in map:
            map[line[0]] = [int(line[1]), trans(line[2], line[3]), trans(line[4], line[5])]
        else:
            map[line[0]][0] += int(line[1])
            map[line[0]][1] += trans(line[2], line[3])
            map[line[0]][2] += trans(line[4], line[5])
    # print(map)
    for t in map:
        map[t] = [map[t][0], trans2B(map[t][1]), trans2B(map[t][2])]
        map[t] = [str(i) for i in map[t]]
        print_list = [t, *[str(i) for i in map[t]]]
        print("{:<40} {:>20} {:>15} {:>15}".format(*print_list))

